//<<<<<<< HEAD
//package cn.xspace.wnx.fragment;
//
//import android.text.TextUtils;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.widget.AdapterView;
//import android.widget.CheckBox;
//
//import com.xspace.android.xafcommon.util.HypyUtil;
//import com.xspace.android.xafcommon.util.LogUtil;
//import cn.xspace.library.util.MyInfoUtil;
//import com.xspace.android.xafcommon.view.MyListView;
//
//import java.util.ArrayList;
//import java.util.Collections;
//import java.util.Comparator;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import com.xspace.android.xafcommon.base.BaseFragment;
//import cn.xspace.wnx.R;
//import cn.xspace.wnx.adapter.ContactListAdapter;
//import cn.xspace.wnx.db.OrgAllUserDao;
//import cn.xspace.library.bean.OrgDeptUserBean;
//import com.xspace.android.xafcommon.util.EventBusConstant;
//import de.greenrobot.event.EventBus;
//import rx.Subscriber;
//import rx.android.schedulers.AndroidSchedulers;
//import rx.functions.Action1;
//import rx.schedulers.Schedulers;
//
///**
// * Created by liuchen on 2016/11/1.
// */
//public class SelectedMemberFragment extends BaseFragment {
//    private static final String TAG = "AddressBookSelectFragme";
//    private List<OrgDeptUserBean> dataList;
//    private MyListView dataListview;
//    private ContactListAdapter mAdapter;
//    private String user_id = "";
//    private String dept_id = "";
//
//    public SelectedMemberFragment() {
//        super();
//    }
//
//    @Override
//    public View initView(LayoutInflater inflater) {
//        return inflater.inflate(R.layout.fragment_addressbook_list_select, null);
//    }
//
//    @Override
//    protected void initFindViewById(View view) {
//        dataListview = (MyListView) view.findViewById(R.id.listview_addressbook);
//        dataList = new ArrayList<>();
//    }
//
//    @Override
//    protected void initEvent() {
//        super.initEvent();
//        dataListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                View checkbox = view.findViewById(R.id.check_select);
//
//                if (checkbox != null && checkbox instanceof CheckBox) {
//                    boolean state = ((CheckBox) checkbox).isChecked();
//                    ((CheckBox) checkbox).setChecked(!state);
//                    listener.orgUserCheck(position, dataList.get(position), !state);
//                } else {
//                    LogUtil.d("找不到checkbox");
//                }
//
//            }
//        });
//
//    }
//
//    @Override
//    public void initData() {
//        user_id = MyInfoUtil.getMyUserid(mContext);
//        dept_id = MyInfoUtil.getMyDeptId(mContext);
//
//        getLocalData();
//    }
//
//    private void getLocalData() {
//        registerSubscription( OrgAllUserDao.getInstance().getOrgUserData().getOrgUserList()
//                .subscribeOn(Schedulers.io())
//                .doOnNext(new Action1<List<OrgDeptUserBean>>() {
//                    @Override
//                    public void call(List<OrgDeptUserBean> orgDeptUserBeenList) {
//                        for (OrgDeptUserBean bean : orgDeptUserBeenList) {
//                            bean.shotKey = HypyUtil.cn2py(bean.user_name);
//                        }
//                        Collections.sort(orgDeptUserBeenList, new Comparator<OrgDeptUserBean>() {
//                            @Override
//                            public int compare(OrgDeptUserBean lhs, OrgDeptUserBean rhs) {
//                                if (TextUtils.isEmpty(lhs.shotKey)) {
//                                    return -1;
//                                }
//                                String key1 = lhs.shotKey.toUpperCase();
//                                Integer num1 = HypyUtil.chartSortMap.get(key1);
//                                String key2 = rhs.shotKey.toUpperCase();
//                                Integer num2 = HypyUtil.chartSortMap.get(key2);
//                                if (num1 == null) {
//                                    return -1;
//                                }
//                                if (num2 == null) {
//                                    return 1;
//                                }
//                                return num1.compareTo(num2);
//                            }
//                        });
//                    }
//                })
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(dataGet));
//        //获取本地数据
//    }
//
//
//    Subscriber<List<OrgDeptUserBean>> dataGet = new Subscriber<List<OrgDeptUserBean>>() {
//        @Override
//        public void onCompleted() {
//            LogUtil.d(TAG, "onCompleted");
//        }
//
//        @Override
//        public void onError(Throwable e) {
//            e.printStackTrace();
//            LogUtil.d(TAG, "onError");
//            //网络请求出错读取数据库
//        }
//
//        @Override
//        public void onNext(List<OrgDeptUserBean> o) {
//            LogUtil.d(TAG, "onNext>>>" + o.size());
//            for (OrgDeptUserBean bean : o) {
//                LogUtil.d(TAG, "onNext>>>>>>>>>" + bean.shotKey);
//            }
//            dataList = o;
//=======
//package cn.xspace.wnx.fragment;
//>>>>>>> masterWnx
//
//import android.text.TextUtils;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.widget.AdapterView;
//import android.widget.CheckBox;
//
//import com.xspace.android.xafcommon.util.HypyUtil;
//import com.xspace.android.xafcommon.util.LogUtil;
//import com.xspace.android.xafcommon.util.MyInfoUtil;
//import com.xspace.android.xafcommon.view.MyListView;
//
//import java.util.ArrayList;
//import java.util.Collections;
//import java.util.Comparator;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import com.xspace.android.xafcommon.base.BaseFragment;
//import cn.xspace.wnx.R;
//import cn.xspace.wnx.adapter.ContactListAdapter;
//import cn.xspace.wnx.db.OrgAllUserDao;
//import cn.xspace.library.bean.OrgDeptUserBean;
//import com.xspace.android.xafcommon.util.EventBusConstant;
//import de.greenrobot.event.EventBus;
//import rx.Subscriber;
//import rx.android.schedulers.AndroidSchedulers;
//import rx.functions.Action1;
//import rx.schedulers.Schedulers;
//
///**
// * Created by liuchen on 2016/11/1.
// */
//public class SelectedMemberFragment extends BaseFragment {
//    private static final String TAG = "AddressBookSelectFragme";
//    private List<OrgDeptUserBean> dataList;
//    private MyListView dataListview;
//    private ContactListAdapter mAdapter;
//    private String user_id = "";
//    private String dept_id = "";
//
//    public SelectedMemberFragment() {
//        super();
//    }
//
//    @Override
//    public View initView(LayoutInflater inflater) {
//        return inflater.inflate(R.layout.fragment_addressbook_list_select, null);
//    }
//
//    @Override
//    protected void initFindViewById(View view) {
//        dataListview = (MyListView) view.findViewById(R.id.listview_addressbook);
//        dataList = new ArrayList<>();
//    }
//
//    @Override
//    protected void initEvent() {
//        super.initEvent();
//        dataListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                View checkbox = view.findViewById(R.id.check_select);
//
//                if (checkbox != null && checkbox instanceof CheckBox) {
//                    boolean state = ((CheckBox) checkbox).isChecked();
//                    ((CheckBox) checkbox).setChecked(!state);
//                    listener.orgUserCheck(position, dataList.get(position), !state);
//                } else {
//                    LogUtil.d("找不到checkbox");
//                }
//
//            }
//        });
//
//    }
//
//    @Override
//    public void initData() {
//        user_id = MyInfoUtil.getMyUserid(mContext);
//        dept_id = MyInfoUtil.getMyDeptId(mContext);
//
//        getLocalData();
//    }
//
//    private void getLocalData() {
//        registerSubscription( OrgAllUserDao.getInstance().getOrgUserData().getOrgUserList()
//                .subscribeOn(Schedulers.io())
//                .doOnNext(new Action1<List<OrgDeptUserBean>>() {
//                    @Override
//                    public void call(List<OrgDeptUserBean> orgDeptUserBeenList) {
//                        for (OrgDeptUserBean bean : orgDeptUserBeenList) {
//                            bean.shotKey = HypyUtil.cn2py(bean.user_name);
//                        }
//                        Collections.sort(orgDeptUserBeenList, new Comparator<OrgDeptUserBean>() {
//                            @Override
//                            public int compare(OrgDeptUserBean lhs, OrgDeptUserBean rhs) {
//                                if (TextUtils.isEmpty(lhs.shotKey)) {
//                                    return -1;
//                                }
//                                String key1 = lhs.shotKey.toUpperCase();
//                                Integer num1 = HypyUtil.chartSortMap.get(key1);
//                                String key2 = rhs.shotKey.toUpperCase();
//                                Integer num2 = HypyUtil.chartSortMap.get(key2);
//                                if (num1 == null) {
//                                    return -1;
//                                }
//                                if (num2 == null) {
//                                    return 1;
//                                }
//                                return num1.compareTo(num2);
//                            }
//                        });
//                    }
//                })
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(dataGet));
//        //获取本地数据
//    }
//
//
//    Subscriber<List<OrgDeptUserBean>> dataGet = new Subscriber<List<OrgDeptUserBean>>() {
//        @Override
//        public void onCompleted() {
//            LogUtil.d(TAG, "onCompleted");
//        }
//
//        @Override
//        public void onError(Throwable e) {
//            e.printStackTrace();
//            LogUtil.d(TAG, "onError");
//            //网络请求出错读取数据库
//        }
//
//        @Override
//        public void onNext(List<OrgDeptUserBean> o) {
//            LogUtil.d(TAG, "onNext>>>" + o.size());
//            for (OrgDeptUserBean bean : o) {
//                LogUtil.d(TAG, "onNext>>>>>>>>>" + bean.shotKey);
//            }
//            dataList = o;
////
//            mAdapter = new ContactListAdapter(mContext, dataList, null, true);
//            mAdapter.setiOrgUserCheckListener(listener);
//            dataListview.setAdapter(mAdapter);
//            mAdapter.notifyDataSetChanged();
//        }
//    };
//
//    ContactListAdapter.IOrgUserCheckListener listener = new ContactListAdapter.IOrgUserCheckListener() {
//        @Override
//        public void orgUserCheck(int postion, OrgDeptUserBean bean, boolean isChecked) {
//            LogUtil.d(bean.toString());
//            bean.isSelectd = isChecked;
//            //通知acitivity更新
//            Map<String, Object> toActivityMap = new HashMap<>();
//            toActivityMap.put(EventBusConstant.TYPE, EventBusConstant.ADDRESSBOOK_TO_ACTIVITY);
//            toActivityMap.put(EventBusConstant.SINGLE_MEMBER, bean);
//            toActivityMap.put(EventBusConstant.SELECT_OR_CANCEM, isChecked);
//            EventBus.getDefault().post(toActivityMap);
//
//            Map<String, Object> toFragmentMap = new HashMap<>();
//            toFragmentMap.put(EventBusConstant.TYPE, EventBusConstant.ADDRESSBOOK_TO_ORGANIZATION);
//            toFragmentMap.put(EventBusConstant.SELECT_OR_CANCEM, isChecked);
//            toFragmentMap.put(EventBusConstant.OPERATE_ID, bean.user_id);
//            EventBus.getDefault().post(toFragmentMap);
//        }
//    };
//
//    /**
//     * @param operateId
//     * @param isSelectCancel
//     */
//    private void updateBeanById(String operateId, boolean isSelectCancel) {
//        int cancelPosition = -1;
//        for (OrgDeptUserBean bean : dataList) {
//            if (!TextUtils.isEmpty(operateId) && operateId.equals(bean.user_id)) {
//                //找到取消的bean
//                cancelPosition = dataList.indexOf(bean);
//                break;
//            }
//        }
//        int visiblePostion = dataListview.getFirstVisiblePosition();
//        if (cancelPosition - visiblePostion >= 0) {
//            View view = dataListview.getChildAt(cancelPosition - visiblePostion).findViewById(R.id.check_select);
//            if (view != null && view instanceof CheckBox) {
//                ((CheckBox) view).setChecked(isSelectCancel);
//            }
//        }
//    }
//
//    @Override
//    public void onEventMainThread(Map inParam) {
//        LogUtil.d(inParam.toString());
//        super.onEventMainThread(inParam);
//        if (inParam.get(EventBusConstant.TYPE) == null) {
//            return;
//        }
//        String type = inParam.get(EventBusConstant.TYPE).toString();
//        if (type.equals(EventBusConstant.ACTIVITY_TO_ADDRESSBOOK)) {
//            String id = (String) inParam.get(EventBusConstant.OPERATE_ID);
//            updateBeanById(id, false);
//
//        } else if (type.equals(EventBusConstant.ORGANIZATION_TO_ADDRESSBOOK)) {
//            boolean isSelectCancel = (Boolean) inParam.get(EventBusConstant.SELECT_OR_CANCEM);
//            String numberSelect = (String) inParam.get(EventBusConstant.NUMBER_SELECT);
//            if (EventBusConstant.SINGLE_MEMBER.equals(numberSelect)) {
//                String id = (String) inParam.get(EventBusConstant.OPERATE_ID);
//                //选择单个
//                updateBeanById(id, isSelectCancel);
//            } else if (EventBusConstant.LIST_MEMBER.equals(numberSelect)) {
//                //选择多个
//                List<OrgDeptUserBean> operateList = (List<OrgDeptUserBean>) inParam.get(EventBusConstant.LIST_MEMBER);
//                int index = 0;
//                for (OrgDeptUserBean oldBean : dataList) {
//                    for (OrgDeptUserBean newNean : operateList) {
//                        if (oldBean != null && oldBean.user_id.equals(newNean.user_id)) {
//                            oldBean.isSelectd = isSelectCancel;
//                            updateBeanById(oldBean.user_id, isSelectCancel);
//                            break;
//                        }
//                    }
//                    index++;
//                }
//            }
//        }
////        if (inParam.get(EventBusConstant.TYPE).equals(EventBusConstant.ACTION_SELECT_MENBER_FRAGMENT)) {
////            if (EventBusConstant.CANCEL_MEMBER.equals(inParam.get(EventBusConstant.ACTION_KEY))) {
////                OrgDeptUserBean bean = (OrgDeptUserBean) inParam.get(EventBusConstant.ACTION_VALUE);
////                if (dataList != null && dataList.contains(bean)) {
////                    bean.isSelectd = false;
//////                    mDataList.remove(bean);
////                    int postion = dataList.indexOf(bean);
////                    LogUtil.d(postion + "");
////                    int visiblePostion = dataListview.getFirstVisiblePosition();
////                    LogUtil.d(visiblePostion + "");
////                    if (postion - visiblePostion >= 0) {
////                        View view = dataListview.getChildAt(postion - visiblePostion).findViewById(R.id.check_select);
////                        if (view != null && view instanceof CheckBox) {
////                            ((CheckBox) view).setChecked(false);
////                        }
////                    }
////                }
////            }
////        }
////
////        if (inParam.get(EventBusConstant.TYPE).equals(EventBusConstant.ACTION_SELECT_MEMBER_ACTIVITY)) {
////            //选择单个
////            if (EventBusConstant.SINGLE_MEMBER.equals(inParam.get(EventBusConstant.ACTION_KEY))) {
////                OrgDeptUserBean bean = (OrgDeptUserBean) inParam.get(EventBusConstant.ACTION_VALUE);
////                boolean isSelected = (Boolean) inParam.get(EventBusConstant.SELECT_OR_CANCEM);
////                int postion = 0;
////                for (int i = 0; i < dataList.size(); i++) {
////                    if (bean != null && bean.dept_id != null && bean.dept_id.equals(dataList.get(i).user_id)) {
////                        postion = i;
////                        break;
////                    }
////                }
////                LogUtil.d(postion + "");
////                updateListviewItem(postion, isSelected);
////            } else if (EventBusConstant.LIST_MEMBER.equals(inParam.get(EventBusConstant.ACTION_KEY))) {
////                //选择多个
////                List<OrgDeptUserBean> addList = (List<OrgDeptUserBean>) inParam.get(EventBusConstant.ACTION_VALUE);
////                boolean isSelected = (Boolean) inParam.get(EventBusConstant.SELECT_OR_CANCEM);
////                for (OrgDeptUserBean bean : addList) {
////                    for (OrgDeptUserBean innerBean : dataList) {
////                        if (bean.dept_id.equals(innerBean.user_id)) {
////                            updateListviewItem(dataList.indexOf(innerBean), isSelected);
////                        }
////                    }
////                }
////                //选中
////            }
////        }
//    }
//
//    private void updateListviewItem(int postion, boolean isSelected) {
//        int visiblePostion = dataListview.getFirstVisiblePosition();
//        LogUtil.d(visiblePostion + "");
//        if (postion - visiblePostion >= 0) {
//            View view = dataListview.getChildAt(postion - visiblePostion).findViewById(R.id.check_select);
//            if (view != null && view instanceof CheckBox) {
//                ((CheckBox) view).setChecked(isSelected);
//            }
//        }
//    }
//}
